package com.example.myprojectoffeixue;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import java.util.ArrayList;

public class YaoKongAdpter extends BaseAdapter {
    //遥控器列表适配器

    private ArrayList<controllerList> d;
    private LayoutInflater layoutInflater;
    private Context context;

    public YaoKongAdpter(ArrayList<controllerList> d, Context context) {
        super();
        this.d = d;
        this.context = context;

        this.layoutInflater = LayoutInflater.from(context);
    }

    @Override
    public int getCount() {
        // TODO Auto-generated method stub
        return d.size();
    }

    @Override
    public Object getItem(int position) {
        // TODO Auto-generated method stub
        return d.get(position);
    }

    @Override
    public long getItemId(int position) {
        // TODO Auto-generated method stub
        return position;
    }

    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
        // TODO Auto-generated method stub
        ViewHolder h = null;

        if (convertView == null) {
            h = new ViewHolder();
            convertView = layoutInflater.inflate(R.layout.item_yaokongqi, null);
            h.tv = (TextView) convertView.findViewById(R.id.tv_listview);
            h.iv = (ImageView) convertView.findViewById(R.id.iv_listview);

            convertView.setTag(h);
        } else {
            h = (ViewHolder) convertView.getTag();
        }

        h.tv.setText(d.get(position).name);
        if ("06".equals(d.get(position).kind)) {
            h.iv.setImageResource(R.drawable.zykt);


        } else if ("02".equals(d.get(position).kind)) {
            h.iv.setImageResource(R.drawable.jdh);
        } else if ("04".equals(d.get(position).kind)) {
            h.iv.setImageResource(R.drawable.dianshi);
        }


        return convertView;
    }


    class ViewHolder {

        TextView tv;
        ImageView iv;
        ImageView iv1;


    }


}